package com.ccys.db.rely;

import cn.hutool.core.util.IdUtil;
import com.ccys.db.cache.UserUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.text.ParseException;
import java.util.Date;

/**
 */
@Data
@MappedSuperclass
public class BaseEntity implements Serializable {

	private static final long serialVersionUID = 7851560863986579047L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	private String id;

	private Long createdOnUtc;

	private Long updatedOnUtc;

	private String createdBy;
	
	private String updatedBy;
	
	private Integer delFlag;

	/**
	 * 保存前
	 */
	public void preInsert()  {
		this.setCreatedBy(UserUtil.getCurLoginUserId());
		this.setCreatedOnUtc(System.currentTimeMillis());
		this.setCreatedOnUtc(System.currentTimeMillis());
		if (StringUtils.isBlank(this.id)) {
			this.setId(IdUtil.randomUUID());
		}
	}

	/**
	 * 修改前
	 */
	public void preUpdate() {
		this.setUpdatedBy(UserUtil.getCurLoginUserId());
		this.setUpdatedOnUtc(System.currentTimeMillis());
	}

}
